package com.ship.dispatch.mapper;
/**
 *@title SpDispatchSchemeExecuteMapper
 *@description
 *@author yl
 *@create 2023/12/13 0013
 */

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ship.common.core.web.domain.JsonResult;
import com.ship.dispatch.bean.SpDispatchSchemeExecute;
import com.ship.dispatch.bean.boats.info.BoatsEventMessageInfo;
import com.ship.dispatch.model.Vo.MonthlyExecutionCompleteVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public interface SpDispatchSchemeExecuteMapper  extends BaseMapper<SpDispatchSchemeExecute> {
    @Select("SELECT \n" +
            "IF(e.ship_contract_type is null,-1,e.ship_contract_type) as shipContractType,\n" +
            "            IF(e.`status` is null,-2,e.`status`) as `status`,\n" +
            "            COUNT(d.id) as num\n" +
            "            from sp_arrange_scheme_detail d\n" +
            "            LEFT JOIN sp_dispatch_scheme_execute e on d.id = e.arrange_scheme_detail_id\n" +
            "            where d.plan_year = #{planYear}\n" +
            "            GROUP BY e.ship_contract_type,e.`status`")
    List<Map<String,String>> countSchemeInfo(@Param("planYear") String planYear);

    @Select("SELECT  \n" +
            "            IF(e.ship_contract_type is null,-1,e.ship_contract_type) as shipContractType, \n" +
            "                        IF(e.`status` is null,-2,e.`status`) as `status`, \n" +
            "                        COUNT(d.id) as num \n" +
            "                        from sp_arrange_scheme_detail d \n" +
            "                        LEFT JOIN sp_dispatch_scheme_execute e on d.id = e.arrange_scheme_detail_id \n" +
            "                       \n" +
            "                        GROUP BY e.ship_contract_type,e.`status`")
    List<Map<String, String>> countSchemeCount();

    List<String> queryImoList(@Param("startDate") String startDate,@Param("endDate") String endDate);

   List<MonthlyExecutionCompleteVo> queryExecutionComplete(@Param("startDate") String startDate,@Param("endDate") String endDate);

    String queryExecutionCurrentDayComplete(@Param("startDate") String startDate,@Param("endDate") String endDate);

    List<BoatsEventMessageInfo> queryBoatsEventMessageById(@Param("imo") String imo,@Param("startDate") String startDate,@Param("endDate") String endDate);

    Integer queryTransportShipNumber();

    List<SpDispatchSchemeExecute> queryCarryOutNumber();

    @Select("SELECT payment_amount FROM sp_fob_zfzzcdyfk WHERE procee_instance_id = #{proceeInstanceId} AND port = #{port} ORDER BY create_date DESC LIMIT 1")
    BigDecimal getPaymentAmount(@Param("proceeInstanceId") String proceeInstanceId,@Param("port") Object port);

    @Select("SELECT payment_amount FROM sp_fob_zfxzcdyfk WHERE procee_instance_id = #{proceeInstanceId} AND port = #{port} ORDER BY create_date DESC LIMIT 1")
    BigDecimal getPaymentAmountUn(String proceeInstanceId, Object port);
}
